﻿package mortal.game.view.copy.groupCopy.view.groupCopyPanel
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.net.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.scene3D.ai.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.copy.*;
    import mortal.game.view.mainUI.smallMap.view.*;
    import mortal.mvc.core.*;

    public class GroupCopyRightInfoWin extends CopyInfoPanelBase
    {
        private var _bgImg:GImageBitmap;
        private var _bg:ScaleBitmap;
        private var _copyName:GImageBitmap;
        private var _smallMap:SmallMapEmbedView;
        private var _autoFightBtn:GLoadingButton;
        private var _leaveCopyBtn:GLoadingButton;
        private var _tcopy:TCopy;
        private var _playerList:GTileList;
        private var _itemList:Vector.<BaseItem>;
        private static var _instance:GroupCopyRightInfoWin;

        public function GroupCopyRightInfoWin(param1:String = "", param2:int = 250, param3:int = 380)
        {
            this._itemList = new Vector.<BaseItem>;
            super(ImagesConst.copyInfoPanelTitle_groupCopy, 262, 526, 10);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bgImg = UIFactory.gImageBitmap(ImagesConst.groupCopyRightInfoWinBg, 0, -2, _bodySprite, this.resetPos);
            this._smallMap = UIFactory.smallMapEmbedView("", 18, 40, _bodySprite, true);
            this._smallMap.loadMapCallBack = this.mapLoadComplete;
            this._smallMap.run();
            this.pushUIToDisposeVec(UIFactory.bg(17, 39, 231, 30, _bodySprite, ImagesConst.PanelBg));
            this.pushUIToDisposeVec(UIFactory.bg(17, 220, 231, 56, _bodySprite, ImagesConst.PanelBg));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.groupCopyRightInfoWinTxt_6, 25, 232, _bodySprite));
            this._copyName = UIFactory.gImageBitmap("", 25, 45, _bodySprite);
            this._autoFightBtn = UIFactory.gLoadingButton(ResFileConst.autoFightBtn, 20, 345 + 113, 103, 38, _bodySprite);
            this._autoFightBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._leaveCopyBtn = UIFactory.gLoadingButton(ResFileConst.leaveCopyBtn, 140, 345 + 113, 103, 38, _bodySprite);
            this._leaveCopyBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._playerList = UIFactory.tileList(30, 300, 225, 145, _bodySprite);
            this._playerList.columnWidth = 225;
            this._playerList.rowHeight = 25;
            this._playerList.horizontalGap = -1;
            this._playerList.verticalGap = 5;
            this._playerList.setStyle("cellRenderer", GroupCopyRightInfoRender);
            NetDispatcher.addCmdListener(ServerCommand.GroupTowerCopyHurtInfo, this.updatePlayerList);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.GroupTowerCopyHurtInfo, this.updatePlayerList);
            if (this._bg)
            {
                this._bg.dispose(param1);
                this._bg = null;
            }
            this._bgImg.dispose(param1);
            this._bgImg = null;
            this._smallMap.dispose(param1);
            this._smallMap = null;
            this._copyName.dispose(param1);
            this._copyName = null;
            this._autoFightBtn.dispose(param1);
            this._autoFightBtn = null;
            this._leaveCopyBtn.dispose(param1);
            this._leaveCopyBtn = null;
            this._playerList.dispose(param1);
            this._playerList = null;
            this._tcopy = null;
            this._itemList.length = 0;
            super.disposeImpl(param1);
            return;
        }// end function

        private function resetSmallPos() : void
        {
            if (this._smallMap && this._smallMap.bmpMap)
            {
                this._smallMap.x = (262 - this._smallMap.bmpMap.width) * 0.5;
            }
            return;
        }// end function

        private function mapLoadComplete() : void
        {
            CallLater.addCallBack(this.resetSmallPos);
            return;
        }// end function

        private function resetPos() : void
        {
            this._bgImg.x = (this.width - this._bgImg.width) * 0.5;
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            if (event.target == this._leaveCopyBtn)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyClickQuickBtn));
            }
            else if (event.target == this._autoFightBtn)
            {
                AIManager.cancelAll();
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoFight_A));
            }
            return;
        }// end function

        public function set tcopy(param1:TCopy) : void
        {
            this._tcopy = param1;
            this._copyName.imgUrl = "groupCopyName_" + this._tcopy.icon + ".png";
            this._smallMap.smallMapName = "groupCopySmallMap_" + this._tcopy.icon + ".jpg";
            this.createItemList();
            return;
        }// end function

        private function createItemList() : void
        {
            var _loc_2:BaseItem = null;
            var _loc_3:int = 0;
            if (this._itemList.length)
            {
                return;
            }
            var _loc_1:* = this._tcopy.rewardShow.split("#");
            while (_loc_3 < 4)
            {
                
                _loc_2 = UICompomentPool.getUICompoment(BaseItem);
                _loc_2.setItemStyle(ItemStyleConst.Small, ImagesConst.PetItemBg, 4, 4);
                _loc_2.x = 58 + _loc_3 * 48;
                _loc_2.y = 225;
                _loc_2.isShowLock = true;
                var _loc_4:Boolean = false;
                _loc_2.isDropAble = false;
                _loc_2.isDragAble = _loc_4;
                _bodySprite.addChild(_loc_2);
                _loc_2.itemData = new ItemData(int(_loc_1[_loc_3]));
                this._itemList.push(_loc_2);
                this.pushUIToDisposeVec(_loc_2);
                _loc_3++;
            }
            return;
        }// end function

        private function hurtSort(param1:SGroupTowerPlayerHurtInfo, param2:SGroupTowerPlayerHurtInfo) : int
        {
            if (param1.hurt >= param2.hurt)
            {
                return -1;
            }
            return 1;
        }// end function

        private function updatePlayerList(param1:SGroupTowerHurtInfoMsg) : void
        {
            var _loc_4:Object = null;
            var _loc_5:int = 0;
            var _loc_2:* = param1.topInfos;
            _loc_2.sort(this.hurtSort);
            var _loc_3:* = new DataProvider();
            while (_loc_5 < 5)
            {
                
                _loc_4 = {data:_loc_2[_loc_5], index:_loc_5};
                _loc_3.addItem(_loc_4);
                _loc_5++;
            }
            this._playerList.dataProvider = _loc_3;
            return;
        }// end function

        public static function get instance() : GroupCopyRightInfoWin
        {
            if (_instance == null)
            {
                _instance = new GroupCopyRightInfoWin;
            }
            return _instance;
        }// end function

        public static function get isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
